package com.cabd.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.cabd.dao.FolderDao;
import com.cabd.domain.Folder;
import com.cabd.utils.DataSourceUtils;

public class FolderDaoImpl implements FolderDao {

	@Override
	public void add(Folder folders) throws SQLException {
		QueryRunner queryRunner = new QueryRunner(DataSourceUtils.getDataSource());
		
		String sql = "insert into folders values(?,?,?,?,?,?)";
		
		queryRunner.update(sql, folders.getFolderName(), folders.getFileName1(),
			folders.getFileName2(), folders.getFileName3(), folders.getFileName4(), folders.getResultFile());
	}

	@Override
	public void delete(Folder folder) throws SQLException {
		QueryRunner queryRunner = new QueryRunner(DataSourceUtils.getDataSource());
		
		String sql = "delete from folders where folderName=?";
		
		queryRunner.update(sql, folder.getFolderName());
	}

	@Override
	public List<Folder> findAll() throws SQLException {
		QueryRunner queryRunner = new QueryRunner(DataSourceUtils.getDataSource());
		
		String sql = "select * from folders";
		
		List<Folder> query = queryRunner.query(sql, new BeanListHandler<Folder>(Folder.class));
		
		return query;
	}

}
